import API from "../../api/index";
//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    arraylist:[],
    contact_state:0,//联系客服模块是否显示
    phone:'',//联系客服
    wechat:''//公司微信
  },
  //联系客服模块隐藏显示
  contact(e){
    console.log(e.currentTarget.dataset.type)
    //联系客服
    if (e.currentTarget.dataset.type=='service'){
      wx.makePhoneCall({
        phoneNumber: this.data.phone
      })
    } else if (e.currentTarget.dataset.type == 'wechat'){//公司微信
      wx.showModal({
        title: '',
        content: '公司微信：' + this.data.wechat,
        success(res) {
          if (res.confirm) {
            console.log('确定')
          } else if (res.cancel) {
            console.log('取消')
          }
        }
      })
    }
    this.setData({
      contact_state: !this.data.contact_state
    })
  },
  onShow(){
    this._getIndices()
    this._getService()
    this._getWechat()
  },
  //公司微信
  _getWechat(){
    API.getWechat().then(res=>{
      this.setData({
        wechat: res.data.value
      })
    })
  },
  //获取客服
  _getService(){
    API.getService().then(res=>{
      console.log(res.data.value)
      this.setData({
        phone: res.data.value
      })
    })
  },
  //点其他页面的时候，联系客服模块隐藏
  contactfalse(){
    this.setData({
      contact_state: false
    })
  },
  // 请求获取首页数据
  _getIndices(type) {
    let that = this
    API.getIndices().then(res => {
      console.log(res.data)
      this.setData({
        arraylist: res.data.intros
      })
    })
  },
})
